use Dosvid
go

if exists(select 1
		  from sysobjects
		  where name = 'Users')
  drop table Users
go

create table Users
(
  Id int identity(1,1) not null,
  UserName nvarchar(50) not null,
  [Password] nvarchar(20) not null,
  RoleID int not null,
  Active bit not null,
  EMail nvarchar(100) null,
  Emil_UserName nvarchar(50) null,
  EMail_Password nvarchar(20) null,
  EMail_SMTP_Server nvarchar(100) null
)  
go

alter table Users add constraint PK_Users_ID primary key(Id)
go

alter table Users add constraint FK_Users_Roles_RoleID 
      foreign key (RoleID) references Roles(Id) on delete cascade
go

alter table Users with check add constraint DF_Users_Active
      default (1) for Active
go

alter table Users with check add constraint Password_Not_Empty
      check (Len(IsNull([Password],'')) > 0)
go

create unique nonclustered index IX_Users_UserName on Users
       (UserName asc)
go
